package com.zelin.listener;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.exceptions.ClientException;
import com.tensquare.util.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by WF on 2020/12/21 16:30
 */
@Component
@RabbitListener(queues = "sms")
public class ValidCodeMessageListener {
    @Autowired
    private SmsUtil smsUtil;
    @RabbitHandler
    public void getMessage(Map map){
        try {
            System.out.println("map = " + map);
            //1.接受消息
            String mobile = map.get("mobile").toString();
            String code = map.get("code").toString();
            String templateCode = "SMS_148593167";
            String signName = "品优购";
            Map param = new HashMap();
            param.put("code",code);

            //2.向阿里大于发送消息
            smsUtil.sendSms(mobile,templateCode,signName, JSON.toJSONString(param));

        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
